<%-- 
    Document   : Search
    Created on : Dec 8, 2012, 1:27:15 PM
    Author     : ITCreed
--%>

<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Search cart</title>
        <%@include file="../LayoutAdmin/InHead.jsp" %>
        <script language="JavaScript" type="text/javascript">
            function Sell()
            {
                document.frmCartSearch.btnName.value = "Sell";
                frmCartSearch.submit();
            }
            function Delete()
            {
                document.frmCartSearch.btnName.value = "Delete";
                frmCartSearch.submit();
            }
            function Search()
            {
                document.frmCartSearch.btnName.value = "Search";
                frmCartSearch.submit();
            }
            function Detail()
            {
                document.frmCartSearch.btnName.value = "Detail";
                frmCartSearch.submit();
            }
        </script>
    </head>
    <body>
        <div id="horizontal_bar">
            <div id="wrapper">
                <%@include file="../LayoutAdmin/Top.jsp" %>
                <div id="middle">
                    <%@include file="../LayoutAdmin/Middle_Top.jsp" %>
                    <div class="right" style="float: none; width: 960px">
                        <form name="frmCartSearch" id="frmCartSearch" action="../../SearchCartServlet" method="POST">
                            <div style="text-align: center"><h1>Tra cứu giỏ hàng</h1></div>
                            <table class="Table2">
                                <tr>
                                    <td>Loại giỏ hàng:</td>
                                    <td>
                                        <select name="cbxType">
                                            <option value="all">Tất cả</option>
                                            <option value="Yet">Chưa xử lý</option>
                                            <option value="Already">Đã giao hàng</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <th colspan="2">
                                        <input type="button" value="Tìm" name="btnSearch" class="Button1"
                                               onclick="Search()"/>
                                    </th>
                                </tr>
                            </table>
                            <table class="Table3">
                                <tr>
                                    <th>Tên tài khoản</th>
                                    <th>giỏ hàng</th>
                                    <th>Email</th>
                                    <th>Số điện thoại</th>
                                    <th>Tổng tiền</th>
                                    <th>Tình trạng</th>
                                </tr>
                                <%
                                    BO.CartBO cartBO = new BO.CartBO();
                                    List listcart = new ArrayList<Bean.CartBean>();

                                    String key = null;
                                    if (request.getQueryString() != null) {
                                        key = request.getQueryString().split("=")[1];
                                        if (key.equals("all")) {
                                            listcart = cartBO.GetAll();
                                        } else {
                                            listcart = cartBO.GetListByType(key);
                                        }
                                    } else {
                                        listcart = cartBO.GetAll();
                                    }

                                    for (int i = 0; i < listcart.size(); i++) {
                                        Bean.CartBean cartTemp = (Bean.CartBean) listcart.get(i);
                                %>

                                <tr>
                                    <td><%= cartTemp.getAccount_ID().getName()%></td>
                                    <td><%= cartTemp.getID()%></td>
                                    <td><%= cartTemp.getAccount_ID().getEmail()%></td>
                                    <td><%= cartTemp.getAccount_ID().getPhone()%></td>
                                    <td><%= cartTemp.getCost()%></td>
                                    <td><%= cartTemp.getState()%></td>
                                    
                                    <% session.setAttribute("cart", cartTemp);                  
                                    if (cartTemp.getState().equals("Yet")) {%>
                                    <td><input type="button" value="Giao hàng" name="btnSell" class="Button1"
                                               onclick="Sell()"/></td>                                        
                                    <td><input type="button" value="Xóa giỏ" name="btnDelete" class="Button1"
                                               onclick="Delete()"/></td>
                                    <td><input type="button" value="Chi tiết" name="btnDetail" class="Button1"
                                               onclick="Detail()"/></td>
                                        <%}%>
                                </tr>
                                <%
                                    }
                                %>
                            </table>
                            <input type="hidden" value="" name="btnName"/>
                        </form>
                    </div>
                </div>
                <%@include file="../LayoutUser/Bottom.jsp" %>
            </div>
        </div>
    </body>
</html>
